using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace ARD.Data
{
    public class DbTypeToTypeMap
    {
        public static Type ToType(DbType dbType)
        {
            if (dbType == DbType.Boolean)
            {
                return typeof(bool);
            }
            else if (dbType == DbType.Byte || dbType == DbType.SByte)
            {
                return typeof(byte);
            }
            else if (dbType == DbType.Int16)
            {
                return typeof(Int16);
            }
            else if (dbType == DbType.Int32)
            {
                return typeof(Int32);
            }
            else if (dbType == DbType.Int64)
            {
                return typeof(Int64);
            }
            else if (dbType == DbType.UInt16)
            {
                return typeof(UInt16);
            }
            else if (dbType == DbType.UInt32)
            {
                return typeof(UInt32);
            }
            else if (dbType == DbType.UInt64)
            {
                return typeof(UInt64);
            }
            else if (dbType == DbType.Single)
            {
                return typeof(float);
            }
            else if (dbType == DbType.Double || dbType == DbType.VarNumeric)
            {
                return typeof(Double);
            }
            else if (dbType == DbType.Decimal || dbType == DbType.Currency)
            {
                return typeof(Decimal);
            }
            else if (
                   dbType == DbType.AnsiString
                || dbType == DbType.AnsiStringFixedLength
                || dbType == DbType.String
                || dbType == DbType.StringFixedLength)
            {
                return typeof(string);
            }
            else if (dbType == DbType.Binary)
            {
                return typeof(byte[]);
            }
            else if (dbType == DbType.Guid)
            {
                return typeof(Guid);
            }
            else if(
                    dbType == DbType.Date
                 || dbType == DbType.Time
                 || dbType == DbType.DateTime
                 || dbType == DbType.DateTime2)
            {
                return typeof (DateTime);
            }
            else if(dbType == DbType.DateTimeOffset)
            {
                return typeof (TimeSpan);
            }
            else if(dbType == DbType.Xml)
            {
                return typeof (string);
            }
            else if (dbType == DbType.Object)
            {
                return typeof(object);
            }
            else
            {
                throw new ArgumentException("Unsupported DbType value: " + dbType);
            }
        }
    }
}
